package cn.zglbk.network.context;
import cn.zglbk.network.channel.GameChannelPromise;
import cn.zglbk.network.channel.IMessageSendFactory;
import cn.zglbk.network.gateway.ChannelService;
import cn.zglbk.network.param.GameMessagePackage;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
public class GameGatewayMessageSendFactory implements IMessageSendFactory {
    private ChannelService channelService;

    public GameGatewayMessageSendFactory(ChannelService channelService) {
        this.channelService = channelService;
    }

    @Override
    public void sendMessage(GameMessagePackage gameMessagePackage, GameChannelPromise promise) {
        Channel channel = channelService.getChannel(gameMessagePackage.getHeader().getPlayerId());
        if(channel != null && channel.isActive()){
            channel.writeAndFlush(gameMessagePackage);
        }
    }
}
